using System;
using UnityEngine;
using QFramework;

namespace ProjectSurvivor
{
	public partial class Enemy : ViewController
	{
		public float HP = 3;

		public float MovementSpeed = 2.0f;


		private void Start()
		{
			EnemyGenerator.EnemyCount.Value++;
		}

		private void OnDestroy()
		{
			EnemyGenerator.EnemyCount.Value--;
		}

		private void Update()
        {
			//var player = FindObjectOfType<Player>();
			if (Player.Default)
            {
			var direction = (Player.Default.transform.position - transform.position).normalized;

			transform.Translate(direction * Time.deltaTime * MovementSpeed);
			}

			if (HP <= 0)
            {
	            Global.GeneratePowerUp(gameObject);
				this.DestroyGameObjGracefully();
				
				//To do：经验值的掉落
            }


        }

		private bool mIgnoreHurt = false;
		public void Hurt(float value)
		{						
			if (mIgnoreHurt) return;
			Sprite.color = Color.red;
			var enemyRefCache = this;
			ActionKit.Delay(0.2f,() =>
			{
				HP-= Global.SimpleAbilityDamage.Value;
				Sprite.color = Color.white;
				mIgnoreHurt = false;
			}).Start(this);
		}
	}
}
	

 
